package com.ddwl.goods.controller;

import com.ddwl.common.annotation.Auth;
import com.ddwl.common.constant.BaseEnum;
import com.ddwl.common.controller.BaseController;
import com.ddwl.goods.service.ItemRateService;
import com.ddwl.schema.bo.base.PageBo;
import com.ddwl.schema.bo.goods.ItemRateBo;
import com.ddwl.schema.bo.goods.ItemRatePageBo;
import com.ddwl.schema.vo.base.PageVo;
import com.ddwl.schema.vo.base.RestVo;
import com.ddwl.schema.vo.goods.ItemRateVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @Author hemiaojun
 * @Date 2021/7/1 16:26
 */
@Api(tags = "商品评价")
@RequestMapping("/itemRate")
@RestController
public class ItemRateController extends BaseController {

    @Resource
    private ItemRateService itemRateService;


    /**
     * 评价详情
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @Auth(required = false,product = {BaseEnum.ProductEnum.FENXIAO, BaseEnum.ProductEnum.MALL, BaseEnum.ProductEnum.WBM, BaseEnum.ProductEnum.WBM_OFFICE, BaseEnum.ProductEnum.BYTE_DANCE})
    @ApiOperation("评价详情")
    public RestVo<ItemRateVo> get(@PathVariable("id") String id){
        return RestVo.ok(itemRateService.get(id));
    }

    /**
     * 商品评价
     * @param itemRateBoList
     * @return
     */
    @PostMapping()
    @Auth(product = BaseEnum.ProductEnum.API)
    @ApiOperation(value = "商品评价",hidden = true)
    public RestVo itemRate(@RequestBody List<ItemRateBo> itemRateBoList){
        itemRateService.rate(itemRateBoList);
        return RestVo.ok();
    }

    /**
     * 商品评价分页
     * @param bo
     * @return
     */
    @PostMapping("/page")
    @Auth(required = false,product = {BaseEnum.ProductEnum.FENXIAO, BaseEnum.ProductEnum.MALL, BaseEnum.ProductEnum.WBM, BaseEnum.ProductEnum.WBM_OFFICE, BaseEnum.ProductEnum.BYTE_DANCE})
    @ApiOperation("商品评价分页查询")
    public RestVo<PageVo<ItemRateVo>> page(@Valid @RequestBody PageBo<ItemRatePageBo> bo){
        return RestVo.ok(itemRateService.page(bo));
    }


}
